﻿using System;
using System.Windows.Markup;
using Petra.Gis.Geometry.Support;
using Petra.Gis.ReferenceSystemServices;
using Petra.Gis.ReferenceSystemServices.Transformations;

namespace testSRST
{
  public class testSRSEquirectangularProj
  {



    public static ProjectedCoordinateSystem createProjection_32662()
    {

      ProjectedCoordinateSystem cs = new ProjectedCoordinateSystem()
      {

        Axes = new AxisList
        {
          // note for axis directions
          new Axis(){ Name = "X", Orientation = Axis.East},
          new Axis(){ Name = "Y", Orientation = Axis.North}
        },
        Metadata = new Metadata()
        {
          Name = "Equirectangular projection",
          Authority = "EPSG",
          AuthorityCode = 32662,
          Abbreviation = "Plate Caree, Cylindrical equirectangular",
          Alias = "Equirectangular",
          Remarks = "simple world projection based on WGS84 ellipsoid"
        },
        DefaultEnvelope = new BoundingBox()
        {
          //Y = 431680, X = 935198; Y = 904554, X=1227672
          Left = -180,
          Bottom = -90,
          Right = 180,
          Top = 90
        },
        Unit = DistanceUnit.ProjectedDegree,
        ProjectionDef = new ProjectionDefinition()
        {
          ClassName = "Equirectangular",
          Metadata = new Metadata()
          {
            Name = "Equirectangular projection",
            Authority = "EPSG",
            AuthorityCode = 32662,
            Abbreviation = "Equirectangular",
            Remarks = "Equirectangular"
          },
          AngularParameterUnit = AngularUnit.Degrees,
          Parameters = new TransformParameters()
          {
            {"standard_parallel_1", 0.0}
          }
        },
        // defined on WGS84
        GeographicCoordinateSystem = new GeographicCoordinateSystem()
        {
          Datum = HorizontalDatum.Wgs1984,
          Axes = new AxisList
          {
            new Axis(){ Name = "E", Orientation = Axis.East},
            new Axis(){ Name = "N", Orientation = Axis.North},
          },
          PrimeMeridian = PrimeMeridian.Greenwich,
          Metadata = new Metadata()
          {
            Name = "WGS84 geographics coordinate system",
            Authority = "EPSG",
            AuthorityCode = 4326,
          }
        }

      };

      return cs;

      string outstr;

      outstr = XamlWriter.Save(cs);
      CoordinateSystem c1 = (CoordinateSystem)XamlReader.Parse(outstr);

      //c1.Axes[0].Orientation = Axis.North;
      //c1.Axes[1].Orientation = Axis.East;


      //Krovak t = new Krovak(cs);

      //XYQuadrantTransform qt = new XYQuadrantTransform(
      //cs,
      //c1,
      //new XParam("FlipX", 0),
      //new XParam("FlipY", 0)
      //);

      //qt.Source = cs;
      //qt.Target = c1;


      //CoordinateSystemTransformCache cc = new CoordinateSystemTransformCache();

      //cc.Transforms.Add(t);
      //cc.Transforms.Add(qt);


      //outstr = XamlWriter.Save(cc);


      //SRSTransform t1 = (SRSTransform)XamlReader.Parse(outstr);


    }




    public static GeographicCoordinateSystem createGeogCS_4326()
    {

      GeographicCoordinateSystem cs = new GeographicCoordinateSystem()
      {
        Unit = AngularUnit.Degrees,
        Datum = HorizontalDatum.Wgs1984,
        Axes = new AxisList
        {
          new Axis(){ Name = "E", Orientation = Axis.East},
          new Axis(){ Name = "N", Orientation = Axis.North},
        },
        PrimeMeridian = PrimeMeridian.Greenwich,
        Metadata = new Metadata()
        {
          Name = "WGS84 geographics coordinate system",
          Authority = "EPSG",
          AuthorityCode = 4326,
        }

      };


      return cs;
    }
  }
}
